<template>
    <div class="page-wrapper">
        <van-icon 
            name="arrow-left" 
            class="back-button" 
            @click="$router.go(-1)" 
            :size="24"
        />
        
        <div class="goods-list">
            <div class="goods-item" v-for="goods in newGoodsList" :key="goods.id">
                <div class="goods-img-container">
                    <img :src="goods.picUrl" :alt="goods.name" class="goods-img">
                    <div class="goods-info-center">
                        <div class="goods-name">{{ goods.name }}</div>
                        <div class="goods-price">¥{{ goods.floorPrice.toFixed(2) }}</div>
                    </div>
                </div>
                <div class="goods-desc">{{ goods.desc }}</div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { getmoreppszg } from "@/api/home";
import { Icon as VanIcon } from "vant"; 

const newGoodsList = ref([]);
const totalPages = 5;

onMounted(async () => {
    for (let page = 1; page <= totalPages; page++) {
        const response = await getmoreppszg(page, 10);
        if (response.data && response.data.list) {
            newGoodsList.value.push(...response.data.list);
        }
    }
});
</script>

<style scoped>
.page-wrapper {
    position: relative;
    padding-top: 10px;
    min-width: 100vh
}

.back-button {
    position: absolute;
    top: 33px;
    left: 85px;
    color: #333;
    background-color: rgba(255, 255, 255, 0.9);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
    cursor: pointer;
}

.goods-list {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.goods-item {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 20px;
}

.goods-img-container {
    position: relative;
    width: 100%;
    padding-top: 60%;
    overflow: hidden;
    border-radius: 12px;
    background-color: #f5f5f5;
}

.goods-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.goods-img-container:hover .goods-img {
    transform: scale(1.02);
}

.goods-info-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    width: 80%;
}

.goods-name {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.goods-price {
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.5);
    display: inline-block;
    padding: 5px 16px;
    border-radius: 20px;
}

.goods-desc {
    font-size: 16px;
    color: #555;
    line-height: 1.5;
    padding: 0 10px;
}
</style>
